package com.optional;

import java.util.Optional;

public class Optional类 {
	public static void main(String[] args) {
		/**
		 * 获取一个空的Optional对象
		 */
		Optional<?> o1 = Optional.empty();
		System.out.println(o1.isEmpty());
		/**
		 * 获取一个可以为空也可以不为空的Optional对象
		 * 当Optional对象不为空对象时，可以使用get方法获取具体的对象，为空时使用get()会报错
		 */
		Optional<?> o2 = Optional.ofNullable("2");
		System.out.println(o2.isPresent());
		System.out.println(o2.get());
		/**
		 * 获取一个非空的Optional对象
		 */
		Optional<?> o3 = Optional.of("test");
		System.out.println(o3.get());
	}
}

class Student{
	private String userName;
	private int userAge;
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public int getUserAge() {
		return userAge;
	}
	public void setUserAge(int userAge) {
		this.userAge = userAge;
	}
	public Student(String userName, int userAge) {
		this.userName = userName;
		this.userAge = userAge;
	}
}